<template>
  <div>
    <el-card class="card1">
      <div class="demo-input-suffix">
        工单编号：
        <el-input
          placeholder="请输入"
          style="width: 200px"
          v-model.trim="params.taskCode"
        >
        </el-input>
        <span class="el-dropdown-link">
          工单状态：
          <el-select
            @visible-change="inputs"
            placeholder="请选择"
            :filterable="true"
            v-model="params.status"
          >
            <el-option
              v-for="item in options"
              :value="item.id"
              :label="item.name"
              :key="item.key"
            ></el-option>
          </el-select>
        </span>
        <el-button type="primary" @click="search">查询</el-button>
      </div>
    </el-card>
    <el-card class="card2">
      <el-button style="background-color: orange; color: white" @click="add"
        >新建</el-button
      >
      <el-button>工单配置</el-button>
      <el-table style="width: 100%" :data="tableData">
        <el-table-column prop="userId" label="序号"></el-table-column>
        <el-table-column prop="taskCode" label="工单编号"></el-table-column>
        <el-table-column prop="innerCode" label="设备编号"> </el-table-column>
        <el-table-column prop="taskType.typeName" label="工单类型">
        </el-table-column>
        <el-table-column prop="手动" label="工单方式"> </el-table-column>
        <el-table-column
          prop="taskStatusTypeEntity.statusName"
          label="工单状态"
        >
        </el-table-column>
        <el-table-column prop="userName" label="运营人员"> </el-table-column>
        <el-table-column prop="createTime" label="创建日期"> </el-table-column>
        <el-table-column prop="do" label="操作">查看详情</el-table-column>
      </el-table>
    </el-card>

    <el-dialog title="新增工单" :visible.sync="dialogFormVisible">
      <el-form :model="form" label-width="80px" :rules="rules">
        <el-form-item label="设备编号" prop="innerCode">
          <el-select
            @visible-change="inputs"
            placeholder="请选择"
            :filterable="true"
          >
            <!-- <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            > -->
            <!-- </el-option> -->
          </el-select>
        </el-form-item>
        <el-form-item label="工单类型" prop="productType">
          <el-input v-model="form.productType"></el-input>
        </el-form-item>
        <el-form-item label="补货清单">
          <el-upload
            class="upload-demo"
            ref="upload"
            action="https://jsonplaceholder.typicode.com/posts/"
          >
            <el-button slot="trigger" size="small" type="info"
              >补货清单</el-button
            >
            <div slot="tip" class="el-upload__tip">
              只能上传jpg/png文件，且不超过500kb
            </div>
          </el-upload>
        </el-form-item>
        <el-form-item label="运营人员" prop="userId">
          <el-input v-model="form.userId" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="desc">
          <el-input v-model="form.desc" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="cancel">取 消</el-button>
          <el-button type="primary" @click="confirm">确 定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getTask, createTask, taskId, getSearchList } from "@/api/user";
export default {
  data() {
    return {
      dialogFormVisible: false,
      options: [
        {
          name: "待办",
          id: 1,
        },
        {
          name: "进行",
          id: 2,
        },
        {
          name: "取消",
          id: 3,
        },
        {
          name: "完成",
          id: 4,
        },
      ],
      tableData: [],
      params: {
        pageIndex: "1",
        pageSize: "10",
        taskCode: "",
        status: "",
      },
      form: {
        createType: "1",
        innerCode: "",
        userId: "",
        productType: "",
        desc: "",
        details: [
          // {
          //   channelCode:,
          //   expectCapacity: "",
          //   skuId: "",
          //   skuName: "",
          //   skuImage: "",
          // },
        ],
      },
      rules: {
        innerCode: [
          { required: true, message: "设备编号不能为空", trigger: "blur" },
        ],
        userId: [
          { required: true, message: "用户id不能为空", trigger: "blur" },
        ],
        productType: [
          { required: true, message: "工单类型不能为空", trigger: "blur" },
        ],
        desc: [{ required: true, message: "描述不能为空", trigger: "blur" }],
      },
    };
  },
  methods: {
    async getTask() {
      const res = await getTask(this.params);
      this.tableData = res.data.currentPageRecords;
      //console.log(this.data);
    },
    add() {
      this.dialogFormVisible = true;
    },
    async confirm() {
      const res = await createTask(this.form);
      console.log(res);
    },
    cancel() {
      this.dialogFormVisible = false;
    },
    async inputs() {
      const res = await taskId(this.value);
      console.log(res);
    },
    async search() {
      const res = await getSearchList(this.params);
      console.log(res.data.currentPageRecords);
      this.tableData = res.data.currentPageRecords;
    },
  },
  created() {
    this.getTask();
  },
};
</script>

<style lang="scss" scoped>
.card1 {
  // height: 65px;
}
.card2 {
  margin-top: 30px;
}
.el-input {
  margin-right: 20px;
}
</style>
